package com.loooooo.pm2024.modules.pm.model;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.loooooo.pm2024.config.BigIDListSerialize;
import com.loooooo.pm2024.config.BigIDSerialize;
import com.loooooo.pm2024.data.BaseEntity;
import com.loooooo.pm2024.modules.sys.model.PrettyUser;

import java.io.Serializable;
import java.util.List;

public class Issue extends BaseEntity implements Serializable {

    private String subject;
    private String content;
    private Integer no;
    private Integer urgent;

    private Integer priority;
    private Integer task;

    private Long expectedFinishTime;

    private Long deadline;
    @JsonSerialize(using = BigIDSerialize.class)
    private Long parentId;
    private Integer top;
    private Integer children;

    @JsonSerialize(using = BigIDSerialize.class)
    private Long ownerId;
    @JsonSerialize(using = BigIDListSerialize.class)

    private List<Long> assignTo;
    private List<PrettyUser> assignToList;

    private Integer standalone;
    private Integer dependent;

    private List<Task> taskList;
    private List<IssueComment> commentList;
    private List<Attachment> attachmentList;

    private List<Issue>  itemList;
    private Integer hung;
    private Long hungAt;
    @JsonSerialize(using = BigIDSerialize.class)
    private Long hungBy;
    private String hungReason;

    private Integer published;
    private Long publishedAt;

    private Long committedAt;

    @JsonSerialize(using = BigIDSerialize.class)
    private Long publishedBy;

    private Integer showIndex;

    private Integer estimatedTime;
    private Long estimatedStartAt;
    private Long estimatedEndAt;

    private Integer approved;
    private Long approvedAt;
    @JsonSerialize(using = BigIDSerialize.class)
    private Long approvedBy;

    private String approvedReason;

    public Integer getApproved() {
        return approved;
    }

    public void setApproved(Integer approved) {
        this.approved = approved;
    }

    public Long getApprovedAt() {
        return approvedAt;
    }

    public void setApprovedAt(Long approvedAt) {
        this.approvedAt = approvedAt;
    }

    public Long getApprovedBy() {
        return approvedBy;
    }

    public void setApprovedBy(Long approvedBy) {
        this.approvedBy = approvedBy;
    }

    public Integer getEstimatedTime() {
        return estimatedTime;
    }

    public void setEstimatedTime(Integer estimatedTime) {
        this.estimatedTime = estimatedTime;
    }

    public Long getEstimatedStartAt() {
        return estimatedStartAt;
    }

    public void setEstimatedStartAt(Long estimatedStartAt) {
        this.estimatedStartAt = estimatedStartAt;
    }

    public Long getEstimatedEndAt() {
        return estimatedEndAt;
    }

    public void setEstimatedEndAt(Long estimatedEndAt) {
        this.estimatedEndAt = estimatedEndAt;
    }

    public Integer getHung() {
        return hung;
    }

    public void setHung(Integer hung) {
        this.hung = hung;
    }

    public Long getHungAt() {
        return hungAt;
    }

    public void setHungAt(Long hungAt) {
        this.hungAt = hungAt;
    }

    public Long getHungBy() {
        return hungBy;
    }

    public void setHungBy(Long hungBy) {
        this.hungBy = hungBy;
    }

    public String getHungReason() {
        return hungReason;
    }

    public void setHungReason(String hungReason) {
        this.hungReason = hungReason;
    }

    public Integer getPublished() {
        return published;
    }

    public void setPublished(Integer published) {
        this.published = published;
    }

    public Long getPublishedAt() {
        return publishedAt;
    }

    public void setPublishedAt(Long publishedAt) {
        this.publishedAt = publishedAt;
    }

    public Long getPublishedBy() {
        return publishedBy;
    }

    public void setPublishedBy(Long publishedBy) {
        this.publishedBy = publishedBy;
    }

    public List<Task> getTaskList() {
        return taskList;
    }

    public void setTaskList(List<Task> taskList) {
        this.taskList = taskList;
    }

    public List<IssueComment> getCommentList() {
        return commentList;
    }

    public void setCommentList(List<IssueComment> commentList) {
        this.commentList = commentList;
    }

    public List<Attachment> getAttachmentList() {
        return attachmentList;
    }

    public void setAttachmentList(List<Attachment> attachmentList) {
        this.attachmentList = attachmentList;
    }
    //id, subject,content,`no`,ownerId,status,urgent,priority,task,

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Integer getNo() {
        return no;
    }

    public void setNo(Integer no) {
        this.no = no;
    }

    public Integer getUrgent() {
        return urgent;
    }

    public void setUrgent(Integer urgent) {
        this.urgent = urgent;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public Integer getTask() {
        return task;
    }

    public Integer task() {
        if (task == null) task = 0;
        return task;
    }

    public void setTask(Integer task) {
        this.task = task;
    }

    public Long getOwnerId() {
        return ownerId;
    }

    public void setOwnerId(Long ownerId) {
        this.ownerId = ownerId;
    }

    public Integer getStandalone() {
        return standalone;
    }

    public void setStandalone(Integer standalone) {
        this.standalone = standalone;
    }

    public Integer getDependent() {
        return dependent;
    }

    public void setDependent(Integer dependent) {
        this.dependent = dependent;
    }

    public Integer getShowIndex() {
        return showIndex;
    }

    public void setShowIndex(Integer showIndex) {
        this.showIndex = showIndex;
    }

    private PrettyUser ownerUser;
    private PrettyUser publishByUser;

    public PrettyUser getOwnerUser() {
        return ownerUser;
    }

    public void setOwnerUser(PrettyUser ownerUser) {
        this.ownerUser = ownerUser;
    }

    public PrettyUser getPublishByUser() {
        return publishByUser;
    }

    public void setPublishByUser(PrettyUser publishByUser) {
        this.publishByUser = publishByUser;
    }

    public Long getCommittedAt() {
        return committedAt;
    }

    public void setCommittedAt(Long committedAt) {
        this.committedAt = committedAt;
    }

    public String getApprovedReason() {
        return approvedReason;
    }

    public void setApprovedReason(String approvedReason) {
        this.approvedReason = approvedReason;
    }

    public List<Long> getAssignTo() {
        return assignTo;
    }

    public void setAssignTo(List<Long> assignTo) {
        this.assignTo = assignTo;
    }

    public List<PrettyUser> getAssignToList() {
        return assignToList;
    }

    public void setAssignToList(List<PrettyUser> assignToList) {
        this.assignToList = assignToList;
    }

    public Long getExpectedFinishTime() {
        return expectedFinishTime;
    }

    public void setExpectedFinishTime(Long expectedFinishTime) {
        this.expectedFinishTime = expectedFinishTime;
    }

    private Boolean timeout;
    public Boolean getTimeout() {
        if(timeout!=null) return timeout;
        if (expectedFinishTime == null || expectedFinishTime < 10000L) return false;
        return expectedFinishTime < System.currentTimeMillis() && getStatus() < 3;
    }

    public void setTimeout(Boolean timeout) {
        this.timeout = timeout;
    }

    public Long getDeadline() {
        return deadline;
    }

    public void setDeadline(Long deadline) {
        this.deadline = deadline;
    }
    private Integer timeLimit;

    public Integer getTimeLimit() {
        return timeLimit;
    }

    public void setTimeLimit(Integer timeLimit) {
        this.timeLimit = timeLimit;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public Integer getTop() {
        return top;
    }

    public void setTop(Integer top) {
        this.top = top;
    }

    public Integer getChildren() {
        return children;
    }

    public void setChildren(Integer children) {
        this.children = children;
    }

    public List<Issue> getItemList() {
        return itemList;
    }

    public void setItemList(List<Issue> itemList) {
        this.itemList = itemList;
    }
}
